package com.hsck.order.kds.main.dialog

import android.content.Context
import android.view.View
import androidx.core.view.GravityCompat
import androidx.drawerlayout.widget.DrawerLayout
import com.hsck.order.kds.base.common.jump
import com.hsck.order.kds.base.utils.LogUtil
import com.hsck.order.kds.login.LoginActivity
import kotlinx.android.synthetic.main.item_personal.view.*
import kotlinx.android.synthetic.main.item_printer.view.*


object PersonalDl {


    fun show(context: Context, viewTop: View, dl: DrawerLayout) {
        val view = viewTop.lin_personal
        viewTop.lin_printer.visibility = View.GONE
        view.visibility = View.VISIBLE
        dl.addDrawerListener(object : DrawerLayout.DrawerListener {
            override fun onDrawerSlide(drawerView: View, slideOffset: Float) {
            }

            override fun onDrawerOpened(drawerView: View) {
                LogUtil.i("onDrawerOpened")
                drawerView.isClickable = true
            }

            override fun onDrawerClosed(drawerView: View) {
            }

            override fun onDrawerStateChanged(newState: Int) {
            }

        })

        dl.addDrawerListener(object : DrawerLayout.DrawerListener {
            override fun onDrawerSlide(p0: View, p1: Float) {
                // 滑动时调用
            }

            override fun onDrawerOpened(p0: View) {
                // 当滑动菜单完全打开时调用
            }

            override fun onDrawerClosed(p0: View) {
                // 当滑动菜单完全关闭时调用
            }

            override fun onDrawerStateChanged(p0: Int) {
                // 滑动状态改变时调用
            }

        })
        view.img_personal_close.setOnClickListener {
            dl.closeDrawer(GravityCompat.END)
        }
        view.tv_item_personal_version.text = "当前版本 ${getVersionName(context)}"
        //退出登录
        view.btn_item_personal_outLogin.setOnClickListener {
            context.jump(LoginActivity::class.java)
        }

    }

    private fun getVersionName(context: Context): String {
        // 获取packagemanager的实例
        val packageManager = context.packageManager
        // getPackageName()是你当前类的包名，0代表是获取版本信息
        val packInfo = packageManager.getPackageInfo(context.packageName, 0)
        val version = "${packInfo.versionName}"
        return version
    }

}